﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSunny.Admin.Controls
{
    public partial class EditYahooOnline : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["idhelp"] != null)
            {
                int idhelp = Convert.ToInt32(Request.QueryString["idhelp"]);
                DataTable dt = DAL.DCollector.DBCollector.Instance.StoredSelectTableWhereID("tbl_HelpOnline", idhelp.ToString());
                txtName.Text = dt.Rows[0]["HelpOnline_Name"].ToString();
                txtEmail.Text = dt.Rows[0]["HelpOnline_Yahoo"].ToString();
                txtSky.Text = dt.Rows[0]["HelpOnline_Sky"].ToString();
                txtPhone.Text = dt.Rows[0]["HelpOnline_Phone"].ToString();

            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            int idhelp = Convert.ToInt32(Request.QueryString["idhelp"]);
            if (fulBigImage.HasFile)
            {
                if (LIB.Validate.CheckFileType(fulBigImage.FileName))
                {
                    string link = fulBigImage.FileName;
                    LIB.Validate saveimage = new LIB.Validate();
                    saveimage.ThayDoiKichThuocAnh(Server.MapPath("/Resources/Images/Image-Support/"), link, 100, fulBigImage.PostedFile.InputStream);
                    string filePathLogo = "/Resources/Images/Image-Support/" + fulBigImage.FileName;

                    DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[5];
                    cl[0] = new DAL.DHelpers.Column("HelpOnline_Image", filePathLogo, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[1] = new DAL.DHelpers.Column("HelpOnline_Name", txtName.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[2] = new DAL.DHelpers.Column("HelpOnline_Yahoo", txtEmail.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[3] = new DAL.DHelpers.Column("HelpOnline_Sky", txtSky.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[4] = new DAL.DHelpers.Column("HelpOnline_Phone", txtPhone.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);

                    string colWhere = "HelpOnline_ID";

                    string colValue = idhelp.ToString();

                    DAL.DCollector.DBCollector.Instance.StoredUpdate("tbl_HelpOnline", cl, colWhere, colValue);
                    Response.Redirect("/Admin/Index.aspx?panel=7&sub=2");
                }
                else
                {
                    Response.Write("<script>alert('Chỉ có thể upload file(.jpg,.png,.jpeg)')</script>");
                }
            }
            else
            {
                DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[4];
               
                cl[0] = new DAL.DHelpers.Column("HelpOnline_Name", txtName.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                cl[1] = new DAL.DHelpers.Column("HelpOnline_Yahoo", txtEmail.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                cl[2] = new DAL.DHelpers.Column("HelpOnline_Sky", txtSky.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                cl[3] = new DAL.DHelpers.Column("HelpOnline_Phone", txtPhone.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);

                string colWhere = "HelpOnline_ID";

                string colValue = idhelp.ToString();

                DAL.DCollector.DBCollector.Instance.StoredUpdate("tbl_HelpOnline", cl, colWhere, colValue);
                Response.Redirect("/Admin/Index.aspx?panel=7&sub=2");
                
            }
        }
    }
}